package com.trainoo.leetcode;

/**
 * <p> 整数反转 </p>
 * https://leetcode-cn.com/problems/reverse-integer/
 *
 * 示例 1:
 * 输入: 123
 * 输出: 321
 *
 * @author tao.zhou
 * @version 1.0
 * @date 2020/6/18 14:13
 */
public class Q0007 {

    public static void main(String[] args) {
        System.out.println(new Solution().reverse(1231231524));
    }

    static class Solution {
        public int reverse(int x) {
            int ans = 0;
            while (x != 0) {
                if ((ans * 10) / 10 != ans) {
                    ans = 0;
                    break;
                }
                ans = ans * 10 + x % 10;
                x = x / 10;
            }
            return ans;
        }
    }
}
